package com.hts.utils;

import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

import java.sql.Time;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class WebClientUtils {
    private WebClient webClient;
    public void init(){
        this.webClient = WebClient.create();
    }

    public static void main(String[] args) {
        WebClient webClient = WebClient.create();

        Mono<String> bodyToMono = webClient
                .get() // GET 请求
                .uri("https://www.baidu.com")  // 请求路径
                .retrieve() // 获取响应体
                .bodyToMono(String.class);//响应数据类型转换
        CountDownLatch countDownLatch = new CountDownLatch(1);
        bodyToMono.subscribe((s)->{
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(s);
            countDownLatch.countDown();
        },throwable -> {

        });

        System.out.println(123);
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

    }

}
